// 年级班级管理
const {sequelize,grade,gradeClass} = require('../dbConfig/index.js')
// 新增年级
const addGrade = async (ctx,next) => {
	const {grade_name,grade_level,grade_school_id} = ctx.request.body
	const result = await grade.create({
		grade_name,
		grade_level,
		grade_school_id
	})
	ctx.body = {
		code:200,
		msg:'添加年级成功',
		data:result
	}
}
//新增班级
const addClass = async (ctx,next)=>{
	const {grade_id,class_name} = ctx.request.body
	const result = await gradeClass.create({
		grade_id,
		class_name
	})
	ctx.body = {
		code:200,
		msg:'添加班级成功',
		data:result
	}
}
// 获取年级及班级列表 
const getGradeAndClass = async (ctx,next)=>{
	const {grade_school_id}= ctx.query
	const result = await grade.findAll({
		attributes:['Id','grade_name','grade_level','grade_school_id'],
		include:[{
			model:gradeClass,
			attributes:['class_id','class_name','grade_id']
		}],
		where:{
			grade_school_id
		}
	})
	ctx.body = {
		code:200,
		msg:'获取年级及班级列表成功',
		data:result
	}
}
module.exports = {
	addGrade,
	addClass,
	getGradeAndClass
}